﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;

namespace Astrid_Desktop
{
    public partial class frmSettings : Form
    {
        private Settings settings = new Settings();

        public frmSettings()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            settings.Username = Encryption.Encrypt(this.txtUsername.Text);
            settings.Password = Encryption.Encrypt(this.txtPassword.Text);
            Serialization.SerializeAsXml(settings, "settings.xml");
            MessageBox.Show("Settings saved", "Settings Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }

        private void frmSettings_Load(object sender, EventArgs e)
        {
            this.CenterToParent();
            settings = Serialization.DeserializeFromXml<Settings>("settings.xml", settings);
            settings.Username = Encryption.Decrypt(settings.Username);
            settings.Password = Encryption.Decrypt(settings.Password);
            this.txtUsername.Text = settings.Username;
            this.txtPassword.Text = settings.Password;
        }
    }
}
